<template>
  <j-modal
    :title="title"
    :width="width"
    :visible="visible"
    :confirmLoading="confirmLoading"
    switchFullscreen
    @ok="handleOk"
    @cancel="handleCancel"
    cancelText="关闭">
    <a-spin :spinning="confirmLoading">
      <a-form :form="form">

        <a-form-item label="袋内码" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['innercode']" placeholder="请输入袋内码"></a-input>
        </a-form-item>
        <a-form-item label="袋外码" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['outercode']" placeholder="请输入袋外码"></a-input>
        </a-form-item>
        <a-form-item label="小程序openid" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['appletopenid']" placeholder="请输入小程序openid"></a-input>
        </a-form-item>
        <a-form-item label="备注" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['note']" placeholder="请输入备注"></a-input>
        </a-form-item>
        <a-form-item label="产品系列" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-select  v-decorator="['project']">
            <a-select-option v-for="item in myoptions":value="item.id":key="item.id">{{item.productname}}</a-select-option>
          </a-select>

        </a-form-item>
        <a-form-item label="积分数" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input-number v-decorator="['integralnumber']" placeholder="请输入积分数" style="width: 100%"/>
        </a-form-item>
        <a-form-item label="渠道" :labelCol="labelCol" :wrapperCol="wrapperCol">
<!--          <a-input v-decorator="['channel']" placeholder="请输入渠道"></a-input>-->
          <a-select  v-decorator="['channel']">
<!--            <a-select-option v-for="item in myoptions":value="item.id":key="item.id">{{item.productname}}</a-select-option>-->
            <a-select-option value="BJQ2">白金Q2</a-select-option>
            <a-select-option value="xlkv3">小龙裤V3</a-select-option>
          </a-select>
        </a-form-item>
        <a-form-item label="内码或外码" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input-number v-decorator="['innerorouter']" placeholder="请输入内码或外码" style="width: 100%"/>
        </a-form-item>
        <a-form-item label="产品" :labelCol="labelCol" :wrapperCol="wrapperCol">


        </a-form-item>
      </a-form>
    </a-spin>
  </j-modal>
</template>

<script>

  import Option from "ant-design-vue/es/vc-mentions/src/Option";
  // alert("world");

  import { httpAction } from '@/api/manage'
  import pick from 'lodash.pick'
  import { validateDuplicateValue } from '@/utils/util'



  export default {
    name: "FillintegralrecordModal",
    components: {
      Option
    },
    data () {

      return {

        // 定义变量myoptions
        myoptions: [],

        form: this.$form.createForm(this),
        title:"操作",
        width:800,
        visible: false,
        model: {},
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },
        confirmLoading: false,
        validatorRules: {
        },
        url: {
          add: "/org.jeecg.modules.com.pointoperation/fillintegralrecord/add",
          edit: "/org.jeecg.modules.com.pointoperation/fillintegralrecord/edit",
          listProduct: "/qrcodeProductList/listAll"

        }
      }
    },
    created () {
    },
    methods: {
      add () {
        this.edit({});
      },
      edit (record) {
        this.form.resetFields();
        this.model = Object.assign({}, record);

        // 接口拿数据，并赋值给myoptions
        httpAction(this.url.listProduct, "" ,"get").then((res)=>{
          if(res.success){

            this.myoptions = res.result;

            console.log(this.myoptions);

            that.$message.success(res.message);
            that.$emit('ok');
          }else{
            that.$message.warning(res.message);
          }
        }).finally(() => {

          // that.confirmLoading = false;
          // that.close();
        });





        this.visible = true;
        this.$nextTick(() => {
          this.form.setFieldsValue(pick(this.model,'innercode','outercode','appletopenid','note','project','integralnumber','channel','innerorouter','qrcodeid'))
        })
      },
      close () {
        this.$emit('close');
        this.visible = false;
      },
      handleOk () {
        const that = this;
        // 触发表单验证
        this.form.validateFields((err, values) => {
          // alert('handle ok');
          // alert(values);



          if (!err) {
            that.confirmLoading = true;
            let httpurl = '';
            let method = '';
            if(!this.model.id){
              httpurl+=this.url.add;
              method = 'post';
            }else{
              httpurl+=this.url.edit;
               method = 'put';
            }
            let formData = Object.assign(this.model, values);
            console.log("表单提交数据",formData)
            httpAction(httpurl,formData,method).then((res)=>{
              if(res.success){
                that.$message.success(res.message);
                that.$emit('ok');
              }else{
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
              that.close();
            })
          }

        })
      },
      handleCancel () {
        this.close()
      },
      popupCallback(row){
        this.form.setFieldsValue(pick(row,'innercode','outercode','appletopenid','note','project','integralnumber','channel','innerorouter','qrcodeid'))
      },


    }
  }
</script>